home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-11-23 | 72.2 KB | 1,960 lines |
- *----------------------------------------------------------------------
- *-- Program...: STRINGS.PRG
- *-- Programmer: Ken Mayer (CIS: 71333,1030)
- *-- Date......: 08/02/1993
- *-- Notes.....: String manipulation routines -- These routines are all
- *-- designed to handle the processing of "Strings"
- *-- (Character Strings). They range from simple checking of
- *-- the location of a string inside another, to reversing
- *-- the contents of a string ... and lots more. See the
- *-- file: README.TXT for details on use of this (and the
- *-- other) library file(s).
- *----------------------------------------------------------------------
-
- FUNCTION Proper
- *----------------------------------------------------------------------
- *-- Programmer..: Clinton L. Warren (VBCES)
- *-- Date........: 07/10/1991
- *-- Notes.......: Returns cBaseStr converted to proper case. Converts
- *-- "Mc", "Mac", and "'s" as special cases. Inspired by
- *-- A-T's CCB Proper function. cBaseStr isn't modified.
- *-- Written for.: dBASE IV, 1.1
- *-- Rev. History: 07/10/1991 1.0 - Original version (VBCES/CLW)
- *-- Calls.......: None
- *-- Called by...: Any
- *-- Usage.......: Proper(<cBaseStr>)
- *-- Example.....: Proper("mcdonald's") returns "McDonald's"
- *-- Returns.....: Propertized string (e.g. "Test String")
- *-- Parameters..: cBaseStr = String to be propertized
- *----------------------------------------------------------------------
-
- PARAMETERS cBaseStr
- private nPos, cDeli, cWrkStr
-
- cWrkStr = lower(m->cBaseStr) + ' ' && space necessary for 's process
-
- nPos = at('mc', m->cWrkStr) && "Mc" handling
- do while nPos # 0
- cWrkStr = stuff(m->cWrkStr, m->nPos, 3, ;
- upper(substr(m->cWrkStr, m->nPos, 1)) ;
- + lower(substr(m->cWrkStr, m->nPos + 1, 1)) ;
- + upper(substr(m->cWrkStr, m->nPos + 2, 1)))
- nPos = at('mc', m->cWrkStr)
- enddo
-
- nPos = at('mac', m->cWrkStr) && "Mac" handling
- do while nPos # 0
- cWrkStr = stuff(m->cWrkStr, m->nPos, 4, ;
- upper(substr(m->cWrkStr, m->nPos, 1)) ;
- + lower(substr(m->cWrkStr, m->nPos + 1, 2)) ;
- + upper(substr(m->cWrkStr, m->nPos + 3, 1)))
- nPos = at('mac', m->cWrkStr)
- enddo
-
- cWrkStr = stuff(m->cWrkStr, 1, 1, upper(substr(m->cWrkStr, 1, 1)))
- nPos = 2
- cDeli = [ -.'"\/`] && standard delimiters
-
- do while nPos <= len(m->cWrkStr) && 'routine' processing
- if substr(m->cWrkStr,m->nPos-1,1) $ m->cDeli
- cWrkStr = stuff(m->cWrkStr, m->nPos, 1, ;
- upper(substr(m->cWrkStr,m->nPos,1)))
- endif
- nPos = m->nPos + 1
- enddo
-
- nPos = at("'S ", m->cWrkStr) && 's processing
- do while m->nPos # 0
- cWrkStr = stuff(m->cWrkStr, m->nPos, 2, ;
- lower(substr(m->cWrkStr, m->nPos, 2)))
- nPos = at('mac', m->cWrkStr)
- enddo
-
- RETURN (m->cWrkStr)
- *-- EoF: Proper()
-
- FUNCTION Dots
- *----------------------------------------------------------------------
- *-- Programmer..: Ken Mayer (CIS: 71333,1030)
- *-- Date........: 12/17/1991
- *-- Notes.......: Based on ideas from Technotes, June, 1990 (see
- *-- JUSTIFY() ), this function should pad a field or
- *-- memvar with dots to the left, right or both sides.
- *-- Note that if the field is too large for the length
- *-- passed (nLength) it will be truncated.
- *-- Written for.: dBASE IV, 1.1
- *-- Rev. History: 12/17/1991 -- Original
- *-- Calls.......: ALLTRIM() Function in PROC.PRG
- *-- Called by...: Any
- *-- Usage.......: Dots(<cFld>,<nLength>,"<cType>")
- *-- Example.....: ?? Dots(Address,25,"R")
- *-- Returns.....: Field/memvar with dot leader/trailer ...
- *-- Parameters..: cFld = Field/Memvar/Character String to justify
- *-- nLength = Width to justify within
- *-- cType = Justification: L=Left, C=Center,R=Right
- *----------------------------------------------------------------------
-
- parameters cFld,nLength,cType
- private cReturn, nVal, nMore
-
- if type("cFld")+type("nLength")+type("cType") $ "CNC,CFC"
-
- cType = upper(m->cType) && just to make sure ...
- cReturn = AllTrim(m->cFld) && trim this puppy on all sides
- if len(cReturn) => m->nLength && check length against parameter
- && truncate if necessary
- cReturn = substr(m->cReturn,1,m->nLength)
- endif
-
- do case
- case cType = "L" && Left -- add trailing dots to field
- cReturn = m->cReturn + ;
- replicate(".",m->nLength-len(m->cReturn))
- case cType = "R" && Right -- add leading dots to field
- cReturn = replicate(".",m->nLength-len(m->cReturn)) + ;
- m->cReturn
- case cType = "C" && Center -- add 'em to both sides ...
- nVal = int( (m->nLength - len(m->cReturn)) / 2)
- *-- here, we have to deal with fractions ...
- nMore = mod(m->nlength - len(m->cReturn), 2)
- *-- add dots on left, field, dots on right (+1 if fraction)
- cReturn = replicate(".",m->nVal)+m->cReturn+;
- replicate(".",m->nVal+iif(m->nMore>0,1,0))
- otherwise && invalid parameter ... return nothing
- cReturn = ""
- endcase
- else
- cReturn = ""
- endif
-
- RETURN m->cReturn
- *-- EoF: Dots()
-
- FUNCTION CutPaste
- *----------------------------------------------------------------------
- *-- Programmer..: Martin Leon (HMAN)
- *-- Date........: 03/05/1992
- *-- Notes.......: Used to do a cut and paste within a field/character
- *-- string. (Taken from an issue of Technotes, can't
- *-- remember which) This function will not allow you to
- *-- overflow the field/char string -- i.e., if the Paste
- *-- part of the function would cause the returned field
- *-- to be longer than it started out, it will not perform
- *-- the cut/paste (STUFF()). For example, if your field
- *-- were 15 characters, and you wanted to replace 5 of
- *-- them with a 10 character string:
- *-- (CutPaste(field,"12345","1234567890"))
- *-- If this would cause the field returned to be longer
- *-- than 15, the function will return the original field.
- *-- Written for.: dBASE IV, 1.1
- *-- Rev. History: Original function 12/17/1991
- *-- 03/05/1992 -- minor change to TRIM(cFLD) in the early
- *-- bits, solving a minor problem with phone numbers that
- *-- Dave Creek (DCREEK) discovered.
- *-- Calls.......: None
- *-- Called by...: Any
- *-- Usage.......: CutPaste(<cFld>,"<cLookFor>","<cRepWith>")
- *-- Example.....: Replace all city with ;
- *-- CutPaste(City,"L.A.","Los Angeles")
- *-- Returns.....: Field with text replaced (or not, if no match found)
- *-- Parameters..: cFld = Field/Memvar/Expression to replace in
- *-- cLookFor = Item to look for (Cut)
- *-- cRepWith = What to replace it with (Paste)
- *----------------------------------------------------------------------
-
- parameters cFld,cLookFor,cRepWith
- private lMatched,nLookLen,nLen,nRepLen,cRetFld,nTrimLen,nCutAt
-
- *-- Make sure they're all character fields/strings
- if type("cFld")+type("cLookFor")+type("cRepWith") # "CCC"
- RETURN m->cFld
- endif
-
- lMatched = .f.
- nLookLen = len(m->cLookFor) && length of field to look for
- nLen = len(m->cFld) && length of original field
- nRepLen = len(m->cRepWith) && length of field to replace with
- cRetFld = trim(m->cFld) && trim it ... (DCREEK's suggestion)
-
- *-- loop will allow a cut/paste to occur more than once in the field
- do while at(m->cLookFor,m->cRetFld) > 0
- lMatched = .t.
- cRetFld = trim(m->cRetFld)
- nTrimLen = len(m->cRetFld)
-
- *-- the following IF statement prevents the replacement text
- *-- from overflowing the length of the original string ...
- if(m->nTrimLen - m->nLookLen) + m->nRepLen > m->nLen
- RETURN m->cRetFld
- endif
-
- *-- here we figure where to "cut" at
- nCutAt = at(m->cLookFor,m->cRetFld)
- *-- let's do the paste ... (using dBASE STUFF() function)
- cRetFld = stuff(m->cRetFld,m->nCutAt,m->nLookLen,m->cRepWith)
- enddo
-
- if .not. lMatched && no match with cLookFor, return original field
- RETURN m->cFld
- endif
-
- RETURN m->cRetFld
- *-- EoF: CutPaste
-
- FUNCTION LastWord
- *----------------------------------------------------------------------
- *-- Programmer..: Martin Leon (HMAN)
- *-- Date........: 12/19/1991
- *-- Notes.......: Returns the last word in a character string.
- *-- Written for.: dBASE IV, 1.1
- *-- Rev. History: 12/19/1991 -- Original
- *-- Calls.......: None
- *-- Called by...: Any
- *-- Usage.......: LastWord("<cString>")
- *-- Example.....: ? LastWord("This is a test string")
- *-- Returns.....: The Last word (bracketed with spaces), i.e.:"string"
- *-- Parameters..: cString = string to be searched
- *----------------------------------------------------------------------
-
- parameters cString
- private cReturn
-
- cReturn = trim(m->cString)
- do while at(" ",m->cReturn) # 0
- cReturn = substr(m->cReturn,at(" ",m->cReturn)+1)
- enddo
-
- RETURN m->cReturn
- *-- EoF: LastWord()
-
- FUNCTION VStretch
- *----------------------------------------------------------------------
- *-- Programmer..: Martin Leon (HMAN -- Ashton Tate/Borland BBS)
- *-- Date........: 10/30/91
- *-- Notes.......: Used to display a long character field, with proper
- *-- word wrap
- *-- Written for.: dBASE IV, 1.1
- *-- Rev. History: Once upon a time, Martin helped me write a more
- *-- complicated routine for use in a browse table. He
- *-- came up with this much less complex version recently
- *-- and sent to me via EMail.
- *-- (10/30/1991 -- Original release for the library)
- *-- Calls.......: None
- *-- Called by...: Any
- *-- Usage.......: ? VStretch( <cLFld>,<nULRow>,<nULCol>,;
- *-- <nBRRow>,<nBRCol> )
- *-- Example.....: ? VStretch( Notes,20,10,24,60,"rg+/gb" )
- *-- Returns.....: "" (Nul)
- *-- Parameters..: cLFld = Long Field to be wrapped on screen
- *-- nULRow = Upper Left Row of window
- *-- nULCol = Upper Left Column
- *-- nBRRow = Bottom Right Row of window
- *-- nBRCol = Bottom Right Column
- *----------------------------------------------------------------------
-
- parameter cLFld,nULRow,nULCol,nBRRow,nBRCol
- private nWinWidth
-
- nWinWidth = ltrim(str((m->nBRCol - m->nULCol)-1,2))
- *-- define window without any border ...
- define window wStretch from m->nULRow,m->nULCol to ;
- m->nBRRow,m->nBRCol none
- activate window wStretch
- *-- make sure window is empty ...
- clear
- *-- display field
- ?? m->cLFld picture "@V"+m->nWinWidth at 0 && @V = word wrap
- save screen to sTemp
- activate screen
- release window wStretch
- restore screen from sTemp
- release screen sTemp
-
- RETURN ""
- *-- EoF: VStretch()
-
- FUNCTION AtCount
- *----------------------------------------------------------------------
- *-- Programmer..: Jay Parsons (CIS: 72662,1302)
- *-- Date........: 03/01/1992
- *-- Notes.......: Get number of times FindString occurs in Bigstring
- *-- Written for.: dBASE IV
- *-- Rev. History: 03/01/1992 -- Original Release
- *-- Calls.......: None
- *-- Called by...: Any
- *-- Usage.......: AtCount("<cFindStr>","<cBigStr>")
- *-- Example.....: ? AtCount("Test","This Test string has Test data")
- *-- Returns.....: Numeric value
- *-- Parameters..: cFindStr = string to find in cBigStr
- *-- cBigStr = string to look in
- *----------------------------------------------------------------------
-
- parameters cFindstr, cBigstr
- private cTarget, nCount
-
- cTarget = m->cBigstr
- nCount = 0
-
- do while .t.
- if at( m->cFindStr,m->cTarget ) > 0
- nCount = m->nCount + 1
- cTarget = substr(m->cTarget, at( m->cFindstr,m->cTarget ) + 1)
- else
- exit
- endif
- enddo
-
- RETURN m->nCount
- *-- EoF: AtCount()
-
- FUNCTION IsAlNum
- *----------------------------------------------------------------------
- *-- Programmer..: Jay Parsons (CIS: 72662,1302)
- *-- Date........: 03/01/1992
- *-- Notes.......: Returns .T. if the first character of cChar is
- *-- alphanumeric, otherwise it is false.
- *-- Written for.: dBASE IV
- *-- Rev. History: 03/01/1992 -- Original Release
- *-- Calls.......: None
- *-- Called by...: Any
- *-- Usage.......: IsAlNum("<cChar>")
- *-- Example.....: ? IsAlNum("Test")
- *-- Returns.....: Logical
- *-- Parameters..: cChar = character string to check for Alphanumeric
- *----------------------------------------------------------------------
-
- parameters cChar
-
- RETURN isalpha( m->cChar ) .or. left( m->cChar, 1 ) $ "0123456789"
- *-- EoF: IsAlNum()
-
- FUNCTION IsAscii
- *----------------------------------------------------------------------
- *-- Programmer..: Jay Parsons (CIS: 72662,1302)
- *-- Date........: 03/01/1992
- *-- Notes.......: Returns .t. if the first character of cChar is in the
- *-- lower half of the ASCII set ( value < 128 )
- *-- Written for.: dBASE IV
- *-- Rev. History: 03/01/1992 -- Original Release
- *-- Calls.......: None
- *-- Called by...: Any
- *-- Usage.......: IsAscii("<cChar>")
- *-- Example.....: ? IsAscii("Teststring")
- *-- Returns.....: Logical
- *-- Parameters..: cChar = string to test
- *----------------------------------------------------------------------
-
- parameters cChar
-
- RETURN asc( m->cChar ) < 128
- *-- EoF: IsAscii()
-
- FUNCTION IsCntrl
- *----------------------------------------------------------------------
- *-- Programmer..: Jay Parsons (CIS: 72662,1302)
- *-- Date........: 03/01/1992
- *-- Notes.......: Returns .t. if the first character of cChar is a
- *-- delete, or a control character.
- *-- Written for.: dBASE IV
- *-- Rev. History: 03/01/1992 -- Original Release
- *-- Calls.......: None
- *-- Called by...: Any
- *-- Usage.......: IsCntrl("<cChar>")
- *-- Example.....: ? IsCntrl("Test")
- *-- Returns.....: Logical
- *-- Parameters..: cChar = string to test
- *----------------------------------------------------------------------
-
- parameters cChar
- private nCharval
-
- nCharval = asc(cChar)
-
- RETURN m->nCharval = 127 .or. m->nCharval < 32
- *-- EoF: IsCntrl()
-
- FUNCTION IsDigit
- *----------------------------------------------------------------------
- *-- Programmer..: Jay Parsons (CIS: 72662,1302)
- *-- Date........: 03/01/1992
- *-- Notes.......: test to see if first character of cChar is a digit
- *-- Written for.: dBASE IV
- *-- Rev. History: 03/01/1992 -- Original Release
- *-- Calls.......: None
- *-- Called by...: Any
- *-- Usage.......: IsDigit("<cChar>")
- *-- Example.....: ? IsDigit("123Test")
- *-- Returns.....: Logical, .T. if first character is a digit
- *-- Parameters..: cChar = string to test
- *----------------------------------------------------------------------
-
- parameters cChar
-
- RETURN left( m->cChar, 1 ) $ "0123456789"
- *-- EoF: IsDigit()
-
- FUNCTION IsPrint
- *----------------------------------------------------------------------
- *-- Programmer..: Jay Parsons (CIS: 72662,1302)
- *-- Date........: 03/01/1992
- *-- Notes.......: Returns .t. if first character of cChar is a printing
- *-- character (space through chr(126) ).
- *-- Written for.: dBASE IV
- *-- Rev. History: Original Release
- *-- Calls.......: None
- *-- Called by...: Any
- *-- Usage.......: IsPrint("<cChar>")
- *-- Example.....: ? IsPrint("Test")
- *-- Returns.....: Logical
- *-- Parameters..: cChar = string to test
- *----------------------------------------------------------------------
-
- parameters cChar
- private nCharval
-
- nCharval = asc(cChar)
-
- RETURN m->nCharval > 31 .and. m->nCharval < 127
- *-- EoF: IsPrint()
-
- FUNCTION IsXDigit
- *----------------------------------------------------------------------
- *-- Programmer..: Jay Parsons (CIS: 72662,1302)
- *-- Date........: 03/01/1992
- *-- Notes.......: Returns .t. if first character of cChar is a possible
- *-- hexidecimal digit.
- *-- Written for.: dBASE IV
- *-- Rev. History: 03/01/1992 -- Original Release
- *-- Calls.......: None
- *-- Called by...: Any
- *-- Usage.......: IsXDigit("<cChar>")
- *-- Example.....: ? IsXDigit("F000")
- *-- Returns.....: Logical
- *-- Parameters..: cChar = string to test
- *----------------------------------------------------------------------
-
- parameters cChar
-
- RETURN left( m->cChar, 1 ) $ "0123456789ABCDEFabcdef"
- *-- EoF: IsXDigit()
-
- FUNCTION IsSpace
- *----------------------------------------------------------------------
- *-- Programmer..: Jay Parsons (CIS: 72662,1302)
- *-- Date........: 03/01/1992
- *-- Notes.......: Returns .T. if first character of cChar is in set of
- *-- space, tab, carriage return, line feed, vertical tab
- *-- or formfeed, otherwise .F. Differs from C function
- *-- of the same name in treating chr(141), used as
- *-- carriage return in dBASE memo fields, as a space.
- *-- Written for.: dBASE IV
- *-- Rev. History: Original Release
- *-- Calls.......: None
- *-- Called by...: Any
- *-- Usage.......: IsSpace("<cChar>")
- *-- Example.....: ? IsSpace(" Test")
- *-- Returns.....: Logical
- *-- Parameters..: cChar = string to test
- *----------------------------------------------------------------------
-
- parameters cChar
- private cSpacestr
-
- cSpacestr = " "+chr(9)+chr(10)+chr(11)+chr(12)+chr(13)+chr(141)
-
- RETURN left( m->cChar, 1 ) $ m->cSpacestr
- *-- EoF: IsSpace()
-
- FUNCTION Name2Label
- *----------------------------------------------------------------------
- *-- Programmer..: Jay Parsons (CIS: 72662,1302)
- *-- Date........: 03/01/1992
- *-- Notes.......: Returns a name held in five separate fields or
- *-- memvars as it should appear on a label of a given
- *-- length in characters. The order of abbreviating is
- *-- somewhat arbitrary--you may prefer to remove the
- *-- suffix before the prefix, or to remove both before
- *-- abbreviating the first name. This can be
- *-- accomplished by rearranging the CASE statements,
- *-- which operate in the order of their appearance.
- *-- Written for.: dBASE IV
- *-- Rev. History: 03/01/1992 -- Original Release
- *-- Calls.......: None
- *-- Called by...: Any
- *-- Usage.......: Name2Label(<nLength>,"<cPrefix>","<cFirstName>",;
- *-- "<cMidName>","<cLastName>","<cSuffix>")
- *-- Example.....: ? Name2Label(20,"The Rev.","Elmore","Norbert",;
- *-- "Smedley","III")
- *-- Returns.....: Character String, in this case "E. N. Smedley, III"
- *-- Parameters..: nLength = length of label
- *-- cPrefix = Prefix to name, such as Mr., Ms., Dr...
- *-- cFirstName = self explanatory
- *-- cMiddleName = self explanatory
- *-- cLastName = self explanatory
- *-- cSuffix = "Jr.", "M.D.", "PhD", etc.
- *----------------------------------------------------------------------
-
- parameters nLength, cPrefix, cFirstname, cMidname, cLastname,cSuffix
- private cTrypref, cTryfirst, cTrymid, cTrylast, cTrysuff, cTryname
-
- cTrypref = ltrim( trim( m->cPrefix ) )
- cTryfirst = ltrim( trim( m->cFirstname ) )
- cTrymid = ltrim( trim( m->cMidname ) )
- cTrylast = ltrim( trim( m->cLastname ) )
- cTrysuff = ltrim( trim( m->cSuffix ) )
- do while .t.
- cTryname = m->cTrylast
- if "" # m->cTrymid
- cTryname = m->cTrymid + " " + m->cTryname
- endif
- if "" # m->cTryfirst
- cTryname = m->cTryfirst + " " + m->cTryname
- endif
- if "" # m->cTrypref
- cTryname = m->cTrypref + " " + m->cTryname
- endif
- if "" # m->cTrysuff
- cTryname = m->cTryname + ", " + m->cTrysuff
- endif
- if len(m->cTryname) <= m->nLength
- exit
- endif
- do case
- case "" # m->cTrymid .AND. right( m->cTrymid, 1 ) # "."
- && convert middle name to initial
- cTrymid = left( m->cTrymid, 1 ) + "."
- case "" # m->cTryfirst .AND. right( m->cTryfirst, 1 ) # "."
- && convert first name to initial
- cTryfirst = left( m->cTryfirst, 1 ) + "."
- case "" # m->cTrypref
- cTrypref = "" && drop prefix
- case "" # m->cTrysuff
- cTrysuff = "" && drop suffix
- case "" # m->cTrymid
- cTrymid = "" && drop middle initial
- case "" # m->cTryfirst
- cTryfirst = "" && drop first initial
- otherwise
- && truncate last name
- cTrylast = left( m->cTrylast, m->nLength )
- endcase
- enddo
-
- RETURN m->cTryName
- *-- EoF: Name2Label()
-
- FUNCTION StrPBrk
- *----------------------------------------------------------------------
- *-- Programmer..: Jay Parsons (CIS: 72662,1302)
- *-- Date........: 03/01/1992
- *-- Notes.......: Search string for first occurrence of any of the
- *-- characters in charset. Returns its position as
- *-- with at(). Contrary to ANSI.C definition, returns
- *-- 0 if none of characters is found.
- *-- Written for.: dBASE IV
- *-- Rev. History: 03/01/1992
- *-- Calls.......: None
- *-- Called by...: Any
- *-- Usage.......: StrPBrk("<cCharSet>","<cBigStr>")
- *-- Example.....: ? StrPBrk("Test","This Test string has Test data")
- *-- Returns.....: Numeric value
- *-- Parameters..: cCharSet = characters to look for in cBigStr
- *-- cBigStr = string to look in
- *----------------------------------------------------------------------
-
- parameters cCharset, cBigstring
- private nPos, nLooklen
-
- nPos = 0
- nLooklen = len( m->cBigstring )
- do while m->nPos < m->nLooklen
- nPos = m->nPos + 1
- if at( substr( m->cBigstring, m->nPos, 1 ), m->cCharset ) > 0
- exit
- endif
- enddo
-
- RETURN iif(nPos=m->nLookLen, 0, m->nPos)
- *-- EoF: StrPBrk()
-
- FUNCTION StrRev
- *----------------------------------------------------------------------
- *-- Programmer..: Jay Parsons (CIS: 72662,1302)
- *-- Date........: 03/01/1992
- *-- Notes.......: Reverses a string of characters
- *-- Written for.: dBASE IV
- *-- Rev. History: 03/01/1992 -- Original Release
- *-- Calls.......: None
- *-- Called by...: Any
- *-- Usage.......: StrRev("<cAnyStr>")
- *-- Example.....: ? StrRev("This is a Test")
- *-- Returns.....: Character string, reversed from original input
- *-- Parameters..: cAnyStr = String of characters to reverse ...
- *----------------------------------------------------------------------
-
- parameters cAnystr
- private cRevstring, nX,nY
-
- nX = len( m->cAnystr )
- nY = 1
- cRevstring = space( m->nX )
- do while m->nX > 0
- cRevstring = stuff(m->cRevstring, m->nY, 1, ;
- substr(m->cAnyStr,m->nX,1))
- nY = m->nY + 1
- nX = m->nX - 1
- enddo
-
- RETURN m->cRevstring
- *-- EoF: StrRev()
-
- FUNCTION Strip2Val
- *----------------------------------------------------------------------
- *-- Programmer..: Jay Parsons (CIS: 72662,1302)
- *-- Date........: 03/01/1992
- *-- Notes.......: Strip characters from the left of a string until
- *-- reaching one that might start a number.
- *-- Written for.: dBASE IV
- *-- Rev. History: 03/01/1992 -- Original Release
- *-- Calls.......: None
- *-- Called by...: Any
- *-- Usage.......: Strip2Val("<cStr>")
- *-- Example.....: ? Strip2Val("Test345")
- *-- Returns.....: character string
- *-- Parameters..: cStr = string to search
- *----------------------------------------------------------------------
-
- parameters cStr
- private cNew
-
- cNew = m->cStr
- do while "" # m->cNew
- if left( m->cNew, 1 ) $ "-.0123456789"
- exit
- endif
- cNew = substr( m->cNew, 2 )
- enddo
-
- RETURN m->cNew
- *-- EoF: Strip2Val()
-
- FUNCTION StripVal
- *----------------------------------------------------------------------
- *-- Programmer..: Jay Parsons (CIS: 72662,1302)
- *-- Date........: 03/01/1992
- *-- Notes.......: Strip characters from the left of the string until
- *-- reaching one that is not part of a number. A hyphen
- *-- following numerics, or a second period,
- *-- is treated as not part of a number.
- *-- Written for.: dBASE IV
- *-- Rev. History: 03/01/1992 -- Original Release
- *-- Calls.......: None
- *-- Called by...: Any
- *-- Usage.......: StripVal("<cStr>")
- *-- Example.....: ? StripVal("123.2Test")
- *-- Returns.....: Character
- *-- Parameters..: cStr = string to test
- *----------------------------------------------------------------------
-
- parameters cStr
- private cNew, cChar, lGotminus, lGotdot
-
- cNew = m->cStr
- store .f. to lGotminus, lGotdot
- do while "" # m->cNew
- cChar = left( m->cNew, 1 )
- do case
- case .not. m->cChar $ "-.0123456789"
- exit
- case m->cChar = "-"
- if m->lGotminus
- exit
- endif
- case m->cChar = "."
- if m->lGotdot
- exit
- else
- lGotdot = .T.
- endif
- endcase
- cNew = substr( m->cNew, 2 )
- lGotminus = .T.
- enddo
-
- RETURN m->cNew
- *-- EoF: StripVal()
-
- FUNCTION ParseWord
- *----------------------------------------------------------------------
- *-- Programmer..: Jay Parsons (CIS: 72662,1302).
- *-- Date........: 07/18/1993
- *-- Notes.......: returns the first word of a string
- *-- Written for.: dBASE IV, 1.1, 1.5
- *-- Rev. History: 04/26/1992 -- Original Release
- *-- 07/18/1993 Add optional separator (Angus Scott-
- *-- Fleming)
- *-- Calls : None
- *-- Called by...: Any
- *-- Usage.......: ? ParseWord(<cString>,[<cSeparator>])
- *-- Example.....: Command = ParseWord( cProgramline )
- *-- Returns.....: That portion, trimmed on both ends, of the passed
- *-- string that includes the characters up to the first
- *-- interior word-separator.
- *-- Parameters..: cString - character string to be stripped.
- *-- cSeparator - optional separating character (default
- *-- is " ")
- *----------------------------------------------------------------------
-
- parameters string, separator
-
- if .not.(type("separator") = "C" .and. len(m->separator)=1)
- separator = " "
- endif
- private cW
- cW = trim( ltrim( m->string ) )
-
- RETURN iif( m->separator $ m->cW, ;
- rtrim(left( m->cW, at( m->separator, m->cW ) - 1 )), m->cW )
- *-- EoF: ParseWord()
-
- FUNCTION StripWord
- *----------------------------------------------------------------------
- *-- Programmer..: Jay Parsons (CIS: 72662,1302).
- *-- Date........: 07/18/1993
- *-- Notes.......: discards first word of a string
- *-- Written for.: dBASE IV, 1.1, 1.5
- *-- Rev. History: 04/26/1992 -- Original Release
- *-- 07/18/1993 Add optional separator (Angus Scott-
- *-- Fleming)
- *-- Calls : None
- *-- Called by...: Any
- *-- Usage.......: ? StripWord(<cString>,[<cSeparator>])
- *-- Examples....: Lastname = StripWord( "Carrie Nation" )
- *-- (returns "Nation")
- *-- InputData = StripWord( "RICHARD;HUGHES;AR;AN",";" )
- *-- (returns HUGHES;AR;AN" )
- *-- Returns.....: string trimmed of trailing spaces, and trimmed on the
- *-- left to remove leading spaces, with the first "word"
- *-- removed. A "word" is defined as all characters up to
- *-- the first space, or up to the first occurrence of the
- *-- specified separator character.
- *-- Parameters..: cString - character string to be stripped.
- *-- cSeparator - optional separating character (default
- *-- is " ")
- *----------------------------------------------------------------------
-
- parameters string, separator
-
- if .not.(type("separator") = "C" .and. len(m->separator)=1)
- separator = " "
- endif
- private cW
- m->cW = trim( ltrim( m->string ) )
-
- RETURN iif( m->separator $ m->cW, ;
- ltrim(substr(m->cW, at( m->separator, m->cW ) + 1)), m->cW )
- *-- EoF: StripWord()
-
- FUNCTION Plural
- *----------------------------------------------------------------------
- *-- Programmer..: Kelvin Smith (KELVIN)
- *-- Date........: 08/27/1992
- *-- Notes.......: Returns number in string form, and pluralized form of
- *-- noun, including converting "y" to "ies", unless the
- *-- "y" is preceded by a vowel. Works with either upper
- *-- or lower case nouns (based on last character).
- *-- : As no doubt all are aware, English includes many
- *-- irregular plural forms; to trap for all is not worth-
- *-- while (how often do you really need to print out die/
- *-- dice?). This should handle the vast majority of needs
- *-- Written for.: dBASE IV, 1.5
- *-- Rev. History: 08/27/1992 1.0 - Original version
- *-- Calls.......: None
- *-- Called by...: Any
- *-- Usage.......: Plural(<nCnt>, <cNoun>)
- *-- Examples....: Plural(1, "flag") returns "1 flag"
- *-- Plural(0, "store") returns "0 stores"
- *-- Plural(5, "COMPANY") returns "5 COMPANIES"
- *-- Returns.....: String with number and noun, no trailing spaces
- *-- Parameters..: nCnt = Count value for noun (how many of cNoun?)
- *-- cNoun = Noun to pluralize
- *----------------------------------------------------------------------
-
- parameters nCnt, cNoun
- private cNounOut, cLast, c2Last, cLast2, lUpper
-
- if nCnt = 1
- m->cNounOut = trim(m->cNoun)
- else
- m->cNounOut = trim(m->cNoun) && No trailing spaces
- cLast = right(m->cNounOut, 1)
- lUpper = isupper(m->cLast) && Upper case?
- cLast = upper(m->cLast)
- c2Last = upper(substr(m->cNounOut, len(m->cNounOut) - 1, 1))
- cLast2 = m->c2Last + m->cLast
-
- * If the noun ends in "Y", normally we change "Y" to "IES".
- * However, if the "Y" is preceded by a vowel, just add "S".
- if m->cLast = "Y" .and. at(m->c2Last, "AEIOU") = 0
- cNounOut = left(m->cNounOut, len(m->cNounOut) - 1) +;
- iif(m->lUpper, "IES", "ies")
- else
- if m->cLast = "S" .or. m->cLast = "X" ;
- .or. m->cLast2 = "CH" .or. m->cLast2 = "SH"
- cNounOut = m->cNounOut + iif(m->lUpper, "ES", "es")
- else
- cNounOut = m->cNounOut + iif(m->lUpper, "S", "s")
- endif
- endif
- endif
-
- RETURN ltrim(str(m->nCnt)) + " " + m->cNounOut
- *-- EoF: Plural()
-
- FUNCTION StrComp
- *----------------------------------------------------------------------
- *-- Programmer..: Sri Raju (Borland Technical Support)
- *-- Date........: 08/01/1992
- *-- Notes.......: From Technotes, August, 1992, "Strings and Things"
- *-- This function compares the contents of two strings.
- *-- If cStr1 is less than cStr2, return -1
- *-- If cStr1 is equal to cStr2, return 0
- *-- If cStr1 is greater than cStr2, return 1
- *-- Written for.: dBASE IV, 1.5
- *-- Rev. History: 08/01/1992 -- Original Release
- *-- Calls.......: None
- *-- Called by...: Any
- *-- Usage.......: StrComp(<cStr1>,<cStr2>)
- *-- Example.....: ? StrComp("TEST","TEXT")
- *-- Returns.....: Numeric (see notes)
- *-- Parameters..: cStr1 = First string
- *-- cStr2 = Second string
- *----------------------------------------------------------------------
-
- parameters cStr1,cStr2
-
- cExact = set("EXACT")
- set exact on
-
- do case
- case m->cStr1 = m->cStr2
- nReturn = 0
- case m->cStr1 > m->cStr2
- nReturn = 1
- case m->cStr1 < m->cStr2
- nReturn = -1
- endcase
-
- set exact &cExact.
-
- RETURN m->nReturn
- *-- EoF: StrComp()
-
- FUNCTION StrOccur
- *----------------------------------------------------------------------
- *-- Programmer..: Sri Raju (Borland Technical Support)
- *-- Date........: 08/01/1992
- *-- Notes.......: TechNotes, August, 1992, "Strings and Things"
- *-- Calculates the number of occurences of a string in
- *-- another given character or memo field.
- *-- Written for.: dBASE IV, 1.5
- *-- Rev. History: 08/01/1992 -- Original Release
- *-- Calls.......: NumOccur() Function in STRINGS.PRG
- *-- Called by...: Any
- *-- Usage.......: StrOccur(<cInString>,<cFindString>)
- *-- Example.....: ? StrOccur("NOTES","every")
- *-- find all occurences of "every" in Memo: NOTES.
- *-- Returns.....: Numeric
- *-- Parameters..: cInString = "Large" string -- to be looked "in". If
- *-- a Memo, name of memo field must be in
- *-- quotes or passed as a memvar and record
- *-- pointer must be on correct record.
- *-- cFindString = "Small" string -- to be found in larger
- *-- string.
- *----------------------------------------------------------------------
-
- parameters cInString, cFindString
-
- nBytes = 0
- lMemo = .f.
- nReturn = 0
-
- if pCount() # 2
- * not enough parameters or too many parameters passed ...
- ?"ERROR. Usage: StrOccur(<string>|<memo fld name>,<string>)"
- RETURN (0)
- endif
- if type("CINSTRING") = "M"
- lMemo = .t.
- else
- RETURN (NumOccur(m->cInstring,m->cFindString))
- endif
-
- *-- process a memo ...
- if m->lMemo
- nTotLen = len(&cInString.)
- n = 1
- nOffSet = 0
- cTempStr = " "
- do while m->nOffSet <= m->nTotLen
- cTempStr = "arr"+ltrim(str(m->n)) && ?
- if (m->nOffSet + 254) > m->nTotLen
- cTempStr = substr(&cInString.,m->nOffSet+1,m->nOffSet+254)
- else
- cTempStr = substr(&cInString.,m->nOffSet+1,m->nTotLen)
- endif
- nReturn = m->nReturn + NumOccur(m->cTempStr,m->cFindStr)
- n = m->n + 1
- nOffSet = m->nOffSet + 254
- enddo
- endif
-
- RETURN (m->nReturn)
- *-- EoF: StrOccur()
-
- FUNCTION NumOccur
- *----------------------------------------------------------------------
- *-- Programmer..: Sri Raju (Borland Technical Support)
- *-- Date........: 08/01/1992
- *-- Notes.......: TechNotes, August, 1992, "Strings and Things"
- *-- Calculates the number of occurences of a string in
- *-- another string.
- *-- Written for.: dBASE IV, 1.5
- *-- Rev. History: 08/01/1992 -- Original Release
- *-- Calls.......: None
- *-- Called by...: StrOccur() Function in STRINGS.PRG
- *-- Usage.......: NumOccur(<cInString>,<cFindString>)
- *-- Example.....: ? NumOccur("This is a string","is")
- *-- Returns.....: Numeric (integer -- # of times string occurs)
- *-- Parameters..: cInString = "Large" string -- to be looked 'in'
- *-- cFindString = "Small" string -- to be looked for
- *----------------------------------------------------------------------
-
- parameters cInString, cFindString
-
- cHoldStr = " "
- nReturn = 0
- cInit = m->cInString
-
- do while len(m->cInit) => 1
- cHoldStr = m->cInit
- if at(m->cFindString,m->cHoldStr) > 0
- nReturn = m->nReturn + 1
- cInit = substr( m->cHoldStr, ;
- at(m->cFindString,m->cHoldStr) + len(m->cFindString) )
- else
- cInit = ""
- endif
- enddo
-
- RETURN (m->nReturn)
- *-- EoF: NumOccur()
-
- FUNCTION ReplMemo
- *----------------------------------------------------------------------
- *-- Programmer..: Sri Raju (Borland Technical Support)
- *-- Date........: 08/01/1992
- *-- Notes.......: TechNotes, August, 1992, "Strings and Things"
- *-- Globally searches and replaces a string with another
- *-- string in a character field/memvar or memo field.
- *-- Written for.: dBASE IV, 1.5
- *-- Rev. History: 08/01/1992 -- Original Release
- *-- Calls.......: MemStuff() Function in STRINGS.PRG
- *-- Called by...: Any
- *-- Usage.......: ReplMemo("cSource",<cCurrStr>,<cNewStr>)
- *-- Example.....: ?ReplMemo("NOTES","Test","testing")
- *-- Returns.....: .T. if a memo field, or character string with changes
- *-- Parameters..: cSource = Source to make changes IN
- *-- cCurrStr = Current string (item(s)) to be changed
- *-- cNewStr = Change 'Current' to this ....
- *----------------------------------------------------------------------
-
- parameters cSource, cCurrStr, cNewStr
-
- cConsole = set("CONSOLE")
-
- nBytes = 0
- nPointer = 0
- nMaster = 0
-
- *-- error
- if pcount() # 3 && valid number of parms
- ?"Error."
- ?"Usage: ReplMemo(<Memo/string>,<Current String>,<New String>)"
- RETURN .f.
- endif
-
- *-- start
- if type(m->cSource) = "M" && if a memo ...
- if len(&cSource.) > 254 && if > 254 char
- cNewFile = (m->cSource)+".TXT" && create a temp file
- erase m->cNewFile
- nPointer = fcreate(m->cNewFile,"A")
- endif
- else
- *-- if not a memo, just perform the replace ...
- RETURN (MemStuff(m->cSource,m->cCurrStr,m->cNewStr))
- endif
-
- *-- memo handling ...
- nTotLen = len(&cSource.)
- nCounter = 1
- nOffSet = 0
- do while m->nOffSet <= m->nTotLen
- cTempStr = "arr"+ltrim(str(m->nCounter))
- if (m->nOffSet+200) < m->nTotLen
- cTempStr = substr(&cSource.,m->nOffSet+1,200)
- else
- cTempStr = substr(&cSource.,m->nOffSet+1,m->nTotLen)
- endif
- cTemp2 = space(200)
- cTemp2 = MemStuff(m->cTempStr, m->cCurrStr, m->cNewStr)
- nBytes = fwrite(m->nPointer,m->cTemp2)
-
- nCounter = m->nCounter + 1
- nOffSet = m->nOffSet + 200
- enddo
-
- nNull = fclose(m->nPointer)
- append memo &cSource. from (m->newfile) overwrite
-
- RETURN .T.
- *-- EoF: ReplMemo()
-
- FUNCTION MemStuff
- *----------------------------------------------------------------------
- *-- Programmer..: Sri Raju (Borland Technical Support)
- *-- Date........: 08/01/1992
- *-- Notes.......: TechNotes, August, 1992, "Strings and Things"
- *-- Replaces a specific string in a character string, by
- *-- another, and returns the resultant string.
- *-- Written for.: dBASE IV, 1.5
- *-- Rev. History: 08/01/1992 -- Original Release
- *-- Calls.......: Stub() Function in STRINGS.PRG
- *-- Called by...: ReplMemo() Funciton in STRINGS.PRG
- *-- Usage.......: MemStuff(<cSource>,<cCurrStr>,<cNewStr>)
- *-- Example.....: ? MemStuff(cTestStr,"Test","Testing")
- *-- Returns.....: Character
- *-- Parameters..: cSource = Source to make changes IN
- *-- cCurrStr = Current string (item(s)) to be changed
- *-- cNewStr = Change 'Current' to this ....
- *----------------------------------------------------------------------
-
- parameters cSource, cCurrStr, cNewStr
- private cSource, cCurrStr, cNewStr
-
- cRetStr = ""
- cHoldStr = ""
- cInitStr = m->cSource
-
- do while len(m->cInitStr) => 1
- cHoldStr = m->cInitStr
- if at(m->cCurrStr,m->cNewStr) > 0
- cTemp = substr(m->cInitStr,1,at(m->cCurrStr,m->cHoldStr))
- nPos = at(m->cCurrStr,m->cHoldStr)
- cReturn = m->cReturn+Stub(m->cTemp,m->nPos,m->cNewStr)
- cInitStr = substr( m->cHoldStr, ;
- at( m->cReplace, m->cHoldStr ) + len(m->cNewStr) )
- else
- cReturn = trim(m->cInitStr)+trim(m->cHoldStr)
- cInitStr = ""
- endif
- enddo
-
- RETURN (m->cReturn)
- *-- EoF: MemStuff()
-
- FUNCTION Stub
- *----------------------------------------------------------------------
- *-- Programmer..: Sri Raju (Borland Technical Support)
- *-- Date........: 08/01/1992
- *-- Notes.......: This returns a specific number of characters from the
- *-- given string specified by the parameter innum, added
- *-- to the third parameter.
- *-- Written for.: dBASE IV, 1.5
- *-- Rev. History: 08/01/1992 -- Original Release
- *-- Calls.......: None
- *-- Called by...: MemStuff() Function in STRINGS.PRG
- *-- Usage.......: Stub(<cString>,nIn,<cIn>)
- *-- Example.....: ? Stub(cTest,5,"Test")
- *-- Returns.....: Character
- *-- Parameters..: cString = Character string to look in
- *-- nIn = # of characters to return
- *-- cIn = characters to add to the end of ...
- *----------------------------------------------------------------------
-
- parameters cString, nIn, cIn
-
- RETURN trim(substr(m->cString,1,m->nIn-1)+m->cIn)
- *-- EoF: Stub()
-
- FUNCTION FirstMem
- *----------------------------------------------------------------------
- *-- Programmer..: Sri Raju (Borland Technical Support)
- *-- Date........: 08/01/1992
- *-- Notes.......: TechNotes, August, 1992, "Strings and Things"
- *-- Capitalizes the first character of all the words in
- *-- the string that is passed as a parameter, and returns
- *-- the resultant string. If a name of a memo field is
- *-- pass as the parameter, it re-writes the memo field,
- *-- and returns a .T.
- *-- Written for.: dBASE IV, 1.5
- *-- Rev. History: 08/01/1992 -- Original Release
- *-- Calls.......: FirstCap() Function in STRINGS.PRG
- *-- Called by...: None
- *-- Usage.......: FirstMem(cInStr)
- *-- Example.....: ? FirstMem("this is a string")
- *-- Returns.....: Either character string with first letter of each
- *-- word capitalized, or .T. (if a Memo).
- *-- Parameters..: cInStr = character string or Memo Field name
- *----------------------------------------------------------------------
-
- parameters cInStr
-
- nBytes = 0
- lMemo = .F.
- lReturn = .T.
- nFPtr = 0
- nMasterCnt = 0
-
- if pcount() # 1
- ? "Error."
- ? "Usage:- FIRSTMEM (<string>) "
- lMemo = .F.
- else
- if type(instr) = "M"
- lMemo = .T.
- cNewFile = (m->cInStr) + ".txt"
- erase (m->cnewfile)
- nFPtr = fcreate(m->cNewFile, "A")
- else
- lReturn = .F.
- endif
- endif
-
- if lMemo
- nTotLen = len(&CInStr.)
- nCntr = 1
- nOffSet = 0
- do while m->nOffSet <= m->nTotLen
- if (m->nOffSet + 250) < m->nTotLen
- cTemp = substr(&cInStr., m->nOffSet + 1, 250)
- else
- cTemp = substr(&CInStr., m->nOffSet + 1, m->nTotLen)
- endif
- cTempStr = space(250)
- cTempStr = FirstCap(m->cTemp)
- nBytes = fwrite(m->nFPtr, m->cTempStr)
-
- nCntr = m->nCntr + 1
- nOffSet = m->nOffSet + 250
- enddo
- x = fclose(m->nFPtr)
- append memo &cInStr. from (m->CNewFile) overwrite
- endif
-
- if lMemo .or. lReturn
- RETURN (.F.)
- else
- RETURN (FirstCap(m->cInStr))
- endif
- *-- EoF: FirstMem()
-
- FUNCTION FirstCap
- *----------------------------------------------------------------------
- *-- Programmer..: Sri Raju (Borland Technical Support)
- *-- Date........: 08/01/1992
- *-- Notes.......: TechNotes, August, 1992, "Strings and Things"
- *-- Capitalizes the first character of a string.
- *-- Written for.: dBASE IV, 1.5
- *-- Rev. History: 08/01/1992 -- Original Release
- *-- Calls.......: None
- *-- Called by...: FirstMem() Function in STRINGS.PRG
- *-- Usage.......: FirstCap(<cInString>)
- *-- Example.....: ?FirstCap("stringofcharacters")
- *-- Returns.....: String with first character captilized.
- *-- Parameters..: cInString = String to cap the first letter of
- *----------------------------------------------------------------------
-
- parameters cInString
- cRetString = ""
- cIStr = m->cInString
-
- do while len(m->cIStr) > 1
- nPos = at(" ", m->cIStr)
- if nPos <> 0
- cRetString = m->cRetString + upper(left(m->cIStr, 1)) + ;
- substr(m->cIStr, 2, m->nPos-1)
- else
- cRetString = m->cRetString + upper(left(m->cIStr, 1)) + ;
- substr(m->cIStr, 2)
- exit
- endif
- do while substr(m->cIStr, m->nPos, 1) = " "
- nPos = m->nPos + 1
- enddo
- cIStr = substr(m->cIStr, m->nPos)
- enddo
-
- RETURN (m->cRetString)
- *-- EoF: FirstCap()
-
- FUNCTION StripND
- *----------------------------------------------------------------------
- *-- Programmer..: Kenneth J. Mayer (CIS: 71333,1030)
- *-- Date........: 01/04/1993
- *-- Notes.......: Strips characters out of a numeric character string
- *-- (like perhaps, a date: 01/04/93 would become 010493)
- *-- Written for.: dBASE IV, 1.5
- *-- Rev. History: 01/04/1993 -- Original Release
- *-- Calls.......: IsDigit() Function in STRINGS.PRG
- *-- Called by...: Any
- *-- Usage.......: StripND(<cNumArg>)
- *-- Example.....: keyboard stripnd(dtoc(date()))
- *-- Returns.....: character string
- *-- Parameters..: cNumArg = Character memvar containing a "numeric"
- *-- string
- *----------------------------------------------------------------------
-
- parameters cNumArg
- private cNumStr, nLen, cRetVal, nCount, cChar
-
- cNumStr = m->cNumArg
- nLen = len(m->cNumStr)
- cRetVal = ""
- nCount = 0
- do while m->nCount <= m->nLen
- nCount = m->nCount + 1
- cChar = substr(m->cNumStr,m->nCount,1)
- if isdigit(m->cChar)
- cRetVal = m->cRetVal+m->cChar
- endif
- enddo
-
- RETURN m->cRetVal
- *-- EoF: StripND()
-
- FUNCTION Strip
- *----------------------------------------------------------------------
- *-- Programmer..: Kenneth Chan [ZAK] (CIS: 72662,1305)
- *-- Date........: 01/05/1993
- *-- Notes.......: Strips out specified character(s) from a string
- *-- Written for.: dBASE IV, 1.5
- *-- Rev. History: 01/05/1993 -- Original Release
- *-- Calls.......: None
- *-- Called by...: Any
- *-- Usage.......: Strip(<cVar>,<cArg>)
- *-- Example.....: ?strip(dtoc(date(),"/")
- *-- Returns.....: Character
- *-- Parameters..: cVar = variable/field to remove character(s) from
- *-- cArg = item to remove from cVar
- *----------------------------------------------------------------------
-
- parameter cVar, cArg
- do while m->cArg $ m->cVar
- cVar = stuff( m->cVar, at( m->cArg, m->cVar ), 1, "" )
- enddo
-
- RETURN m->cVar
- *-- EoF: Strip()
-
- PROCEDURE WordWrap
- *----------------------------------------------------------------------
- *-- Programmer..: David Frankenbach (CIS: 72147,2635)
- *-- Date........: 01/14/1993 (Version 1.1)
- *-- Notes.......: Wraps a long string, breaking it into strings that
- *-- have a maximum length of nWidth. The first output is
- *-- displayed@nRow, nCol. Words are not split ...
- *-- Written for.: dBASE IV, 1.5
- *-- Rev. History: 01/06/1993 -- Original Release (Version 1.0)
- *-- 01/14/1993 -- Version 1.1 -- Corrected side-effect of
- *-- destroying string arg, added test for
- *-- string[nWidth+1] = " "
- *-- Calls.......: None
- *-- Called by...: Any
- *-- Usage.......: do WordWrap with <nRow>, <nCol>, <cString>, <nWidth>
- *-- Example.....: do WordWrap with 2,2,cText,38
- *-- Returns.....: None
- *-- Parameters..: nRow = Row to display first line at
- *-- nCol = Left side of area to display text at
- *-- cString = text to wrap
- *-- nWidth = Width of area to wrap text in
- *----------------------------------------------------------------------
-
- parameters nRow, nCol, cString, nWidth
- private cTemp, nI, cStr
-
- cStr = m->cString && work with a COPY of input, to
- && avoid destroying original
-
- do while len(m->cStr) > 0 && while there's something to work on
- if (m->nWidth < len(m->cStr))
- nI = m->nWidth && look for last " " in first nWidth
-
- if substr(m->cStr, m->nI + 1, 1) # " "
- do while ( (m->nI > 0) .and. ;
- (substr(m->cStr,m->nI,1) # " ") )
- nI = m->nI - 1
- enddo
- endif
-
- if nI = 0 && no spaces
- nI = m->nWidth && get first nWidth characters
- endif
- else
- nI = len(m->cStr) && use the rest of the string
- endif
-
- cTemp = left(m->cStr,m->nI) && get the part to display
-
- if m->nI < len(m->cStr) && remove that part
- cStr = ltrim(substr(m->cStr,m->nI + 1))
- else
- cStr = ""
- endif
-
- *-- display it
- @nRow,nCol say m->cTemp
- *-- move to next row
- nRow = m->nRow + 1
-
- enddo
-
- RETURN
- *-- EoP: WordWrap
-
- FUNCTION BreakName
- *----------------------------------------------------------------------
- *-- Programmer..: Jay Parsons (CIS: 72662,1302)
- *-- Date........: 03/21/1993
- *-- Notes.......: Returns part of a name based on user positioning of
- *-- cursor. This function requires the programmer to set
- *-- up any window desired; the writing surface must have
- *-- a minimum width of 45 characters or the length of the
- *-- name plus 2, whichever is greater, and must be at
- *-- least 4 rows high.
- *-- Written for.: dBASE IV 1.5 ( earlier versions will require changing
- *-- the optional parameter to a required one )
- *-- Rev. History: 03/21/1993 -- Original
- *-- Calls.......: NamePart() function in STRINGS.PRG
- *-- MarkLine() function in STRINGS.PRG
- *-- Called by...: Any
- *-- Usage.......: Breakname("<cName>" [,"<cPart>"] )
- *-- Example.....: LastName = BreakName( "Dr. E. N. Smedley III, "L" )
- *-- Returns.....: character = substring containing part of the name
- *-- Parameters..: cName = Name to parse
- *-- cPart = optional, character from set below:
- *-- P -- prefix( es )
- *-- F -- first name
- *-- M -- middle name or initial
- *-- L -- last name
- *-- S -- suffix( es )
- *----------------------------------------------------------------------
-
- parameters cName, cPart
- private nPos, cP, cParts, nPart, cPrompts, nFirst, nLast, cRet
- private nRow, nCol, nOff
-
- cRet = ""
- store 0 to nPos, nParts, nPart
- cParts = "PFMLS"
- * 1 2 3 4
- * Ruler--> 123456789012345678901234567890123456789012
- cPrompts = "desired part prefix(es) first name " ;
- + "middle name(s)last name suffix(es)"
- if type( "cPart" ) # "C" .or. "" = m->cPart
- nPos = 1
- cP = "?"
- endif
- if m->nPos = 0
- cP = upper( left( ltrim( m->cPart ), 1 ) )
- nPart = at( m->cP, m->cParts )
- endif
- if m->nPart = 0
- nPos = 1
- else
- nPos = NameMark( m->cName, m->cP, "B" )
- nPos = iif( m->nPos = 0, len( m->cName ) + 1, m->nPos )
- endif
- nRow = row()
- nCol = col()
- nOff = int( ( 43 - len( m->cName ) ) / 2 )
- @ m->nRow, m->nCol + m->nOff clear to ;
- m->nRow + 4, m->nCol + max( 45, 45 - m->nOff )
- @ m->nRow, m->nCol say ;
- "Please use the arrow keys to place the cursor"
- @ m->nRow + 1, m->nCol say "on the FIRST character of the "
- @ m->nRow + 1, col() say ;
- trim( substr( m->cPrompts, m->nPart * 14 + 1, 14 ) ) + ":"
- @ m->nRow + 4, m->nCol + m->nOff say ""
- nFirst = MarkLine( m->cName, m->nPos )
- if m->nFirst = 0 .or. m->nFirst > len( m->cName )
- RETURN m->cRet
- endif
- if m->cP = "S"
- nLast = len( trim( m->cName ) )
- else
- @ m->nRow, m->nCol + m->nOff clear to ;
- m->nRow + 4, m->nCol + max( 43, 43 - m->nOff )
- @ m->nRow, m->nCol say ;
- "Please use the arrow keys to place the cursor"
- @ m->nRow + 1, m->nCol say " on the LAST character of the "
- @ m->nRow + 1, col() say ;
- trim( substr( m->cPrompts, m->nPart * 14 + 1, 14 ) ) + ":"
- nPos = NameMark( m->cName, m->cP, "E" )
- @ m->nRow + 4, m->nCol + m->nOff say ""
- nLast = MarkLine( m->cName, m->nPos )
- endif
- if m->nLast > m->nFirst
- cRet = substr(m->cName, m->nFirst, m->nLast - m->nFirst + 1)
- endif
-
- RETURN m->cRet
- *-- EoF: BreakName()
-
- FUNCTION NamePart
- *----------------------------------------------------------------------
- *-- Programmer..: Jay Parsons (CIS: 72662,1302)
- *-- Date........: 03/21/1993
- *-- Notes.......: Guesses which portion of a name held in a single
- *-- variable in the usual printing order corresponds to
- *-- the letter code given for prefix, first name, middle
- *-- names, last name, or suffixes and returns that
- *-- portion. This does not work correctly for all names
- *-- and is recommended to be used only with some human
- *-- interpretation of the results.
- *-- Written for.: dBASE IV 1.5
- *-- Rev. History: 03/21/1993 -- Original
- *-- Calls.......: NameMark() function in STRINGS.PRG
- *-- Called by...: Any
- *-- Usage.......: NamePart( <cName> ,<cPart> )
- *-- Example.....: Suffix = NamePart( "John Doe Jr. Ph. D.", "S" )
- *-- Returns.....: character = substring, part of the name, or null
- *-- string
- *-- Parameters..: cName = Name to parse
- *-- cPart = a character from the set below:
- *-- P -- prefix
- *-- F -- first name
- *-- M -- middle name(s) or initial(s)
- *-- or both
- *-- L -- last name
- *-- S -- suffix(es)
- *----------------------------------------------------------------------
-
- parameters cName, cPart
- private nStart, nStop, cP, nTrimmed, nMark, cN1, cN2
-
- store 0 to nStart, nStop
- cRet = ""
- if type( "cPart" ) # "C" .or. "" = m->cPart .or. "" = m->cName
- RETURN m->cRet
- endif
- cP = upper( left( m->cPart, 1 ) )
- if .not. m->cP $ "PFMLS"
- RETURN m->cRet
- endif
- nStart = NameMark( m->cName, m->cP, "B" )
- nStop = NameMark( m->cName, m->cP, "E" )
- if m->nStop > m->nStart .and. m->nStart > 0
- cRet = substr(m->cName, m->nStart, m->nStop - m->nStart + 1)
- endif
-
- RETURN m->cRet
- *-- EoF: NamePart()
-
- FUNCTION NameMark
- *----------------------------------------------------------------------
- *-- Programmer..: Jay Parsons (CIS: 72662,1302)
- *-- Date........: 03/21/1993
- *-- Notes.......: Guesses which portion of a name held in a single
- *-- variable in the usual printing order corresponds to
- *-- the letter code given for prefix, first name, middle
- *-- names, last name or suffixes and returns the position
- *-- of the character that begins or ends that portion.
- *-- This does not work properly for all names and is
- *-- recommended to be used with MarkLine(), as in
- *-- BreakName().
- *-- Written for.: dBASE IV 1.5
- *-- Rev. History: 03/21/1993 -- Original
- *-- Calls.......: Rat() function in STRINGS.PRG
- *-- Called by...: Any
- *-- Usage.......: NameMark( <cName> ,<cPart>, <cEnd> )
- *-- Example.....: Suffix = NamePart( "John Doe Jr. Ph. D.", "S", "B" )
- *-- Returns.....: numeric = position in cName of requested
- *-- character, or 0, or null string
- *-- Parameters..: cName = Name to parse
- *-- cPart = a character from the set below:
- *-- P -- prefix
- *-- F -- first name
- *-- M -- middle name(s) or initial(s)
- *-- or both
- *-- L -- last name
- *-- S -- suffix(es)
- *-- cEnd = a character from the set below:
- *-- B or F -- first char of the part
- *-- E or L -- last char of the part
- *----------------------------------------------------------------------
-
- parameters cName, cPart, cEnd
- private nStart, nStop, nRet, cP, cE, nTrimmed, nM1, nM2, cN1, cN2,;
- lC
-
- * intialize and check for proper parameters
- store 0 to nStart, nStop, nRet
- if type( "cPart" ) + type( "cName" ) + type( "cEnd" ) # "CCC" ;
- .or. "" = m->cName .or. "" = m->cPart .or. "" = m->cEnd
- RETURN m->nRet
- endif
- cP = upper( left( m->cPart, 1 ) )
- if .not. m->cP $ "PFMLS"
- RETURN m->nRet
- endif
- cE = upper( left( m->cEnd, 1 ) )
- do case
- case m->cE $ "BF"
- cE = "B"
- case m->cE $ "EL"
- cE = "E"
- otherwise
- RETURN m->nRet
- endcase
- * remove end spaces but count leading ones
- cN1 = ltrim( m->cName )
- nTrimmed = len( m->cName ) - len( m->cN1 )
- cN1 = trim( m->cN1 )
- * find interior space; if none we're done
- nM1 = at( " ", m->cN1 )
- if m->nM1 = 0
- cRet = iif( m->cP = "L", m->cN1, "" )
- RETURN m->cRet
- endif
- * anything ending in a period but 1 initial is a prefix
- if m->nM1 > 3 .and. substr( m->cN1, m->nM1 - 1, 1 ) = "."
- if m->cP = "P"
- nStart = 1
- nStop = m->nM1 - 1
- else
- cN2 = ltrim( substr( m->cN1, m->nM1 + 1 ) )
- nTrimmed = m->nTrimmed + len( m->cN1 ) - len( m->cN2 )
- cN1 = m->cN2
- nM1 = at( " ", m->cN1 )
- endif
- else
- if m->cP = "P"
- nStart = 1
- endif
- endif
- * if we're not looking for prefix, first word is first name
- * if not looking for it either, trim it off and adjust space count
- if m->nStart = 0
- if m->cP = "F"
- nStart = 1
- nStop = m->nM1 - 1
- else
- cN2 = ltrim( substr( m->cN1, m->nM1 + 1 ) )
- nTrimmed = m->nTrimmed + len( m->cN1 ) - len( m->cN2 )
- cN1 = m->cN2
- endif
- endif
- * if not done yet, look for suffix. Anything after a comma plus
- * anything ending with period and certain common differentiators
- if m->nStart = 0
- nM1 = at( ",", m->cN1 )
- if m->nM1 > 0
- cN1 = left( m->cN1, m->nM1 - 1 )
- nM2 = m->nM1
- else
- nM2 = len( m->cN1 ) + 1
- endif
- nM1 = rat( " ", m->cN1 )
- lC = .T.
- do while m->lC
- lC = .F.
- if upper( right( m->cN1, 3 ) ) $ "III 2D 2ND 3D 3RD"
- nM1 = len( m->cN1 ) - ;
- iif( left( right( m->cN1, 3 ), 1 ) = " ", 3, 4 )
- cN1 = left( m->cN1, m->nM1 )
- lC = .T.
- nM2 = m->nM1 + 2
- nM1 = rat( " ", m->cN1 )
- endif
- if m->nM1 > 0 .and. "." $ substr( m->cN1, m->nM1 )
- cN1 = left( m->cN1, m->nM1 - 1 )
- cL = .T.
- nM2 = m->nM1 + 1
- nM1 = rat( " ", m->cN1 )
- endif
- enddo
- * the two marks delineate the starts of the last name and suffix
- do case
- case m->cP = "S"
- nStart = m->nM2
- nStop = len( m->cName )
- case m->cP = "L"
- nStart = m->nM1 + 1
- nStop = m->nM2 - 1
- otherwise
- nStart = 1
- nStop = m->nM1 - 1
- endcase
- endif
- if m->nStart < m->nStop
- nStop = min( m->nStop, m->Nstart + len( trim( substr( m->cN1, ;
- m->Nstart, m->Nstop - m->Nstart + 1 ) ) ) - 1 )
- nRet = iif( m->cE = "B", m->nStart, m->nStop ) + m->nTrimmed
- endif
-
- RETURN m->nRet
- *-- EoF: NameMark()
-
- FUNCTION MarkLine
- *----------------------------------------------------------------------
- *-- Programmer..: Jay Parsons (CIS: 72662,1302)
- *-- Date........: 03/21/1993
- *-- Notes.......: Presents a string with cursor at character given by
- *-- numeric offset, allows user to move the cursor within
- *-- the string using arrow keys and returns position
- *-- within string at which cursor is located when edit
- *-- is ended, or 0 if edit is ended by pressing {Esc}.
- *-- The programmer must deal with opening windows,
- *-- positioning the edit, etc. before calling the
- *-- function. Mouse support not supplied.
- *-- Written for.: dBASE IV 1.5
- *-- Rev. History: 03/21/1993 -- Original
- *-- Calls.......: None
- *-- Called by...: Any
- *-- Usage.......: MarkLine( <cLine> [, <nPos> ] )
- *-- Example.....: ? MarkLine( "G. C. K. Chesterton", 10 )
- *-- Returns.....: numeric, character position of the cursor,
- *-- 0 if {Esc}
- *-- Parameters..: cLine = Line to parse
- *-- nPos = optional, default position of cursor
- *-- if omitted, cursor is at first character
- *----------------------------------------------------------------------
-
- parameters cLine, nPos
- private nP, nRet, nCol, cCurs
-
- cCurs = set( "CURSOR" )
- set cursor on
- nP = iif( type( "nPos" ) = "L", 1, m->nPos )
- nRet = m->nP
- nCol = col()
- @ row(), m->nCol say m->cLine
- nKey = 0
- do while m->nKey # 27 .and. m->nKey # 13 .and. m->nKey # 23
- @ row(), m->nCol + m->nRet - 1 say ""
- nKey = inkey( 0 )
- do case
- case m->nKey = 27
- nRet = 0
- case m->nKey = 4 .and. m->nRet < len( m->cLine )
- nRet = m->nRet + 1
- case nKey = 19 .and. m->nRet > 1
- nRet = m->nRet - 1
- endcase
- enddo
- if cCurs = "OFF"
- set cursor off
- endif
-
- RETURN m->nRet
- *-- EoF: MarkLine()
-
- FUNCTION Decode
- *----------------------------------------------------------------------
- *-- Programmer..: Angus Scott-Fleming (CIS: 75500,3223)
- *-- Date........: 11/25/1992 (unknown. Stolen from somewhere....)
- *-- Note........: simple decoding for primitive password protection
- *-- Written for.: dBASE IV 1.1+
- *-- Rev. History: 11/25/1992 -- Original
- *-- Mon 08-02-1993 tuning for performance
- *-- Calls.......: None
- *-- Called by...: Any
- *-- Usage.......: Decode(<cInput>)
- *-- Example.....: Password = Decode(cPassWd)
- *-- Returns.....: decoded string
- *-- Parameters..: <cInput> = encoded string
- *----------------------------------------------------------------------
-
- parameters cInput
- private cString, n
-
- cString = m->cInput
- if isblank(m->cString)
- return m->cString
- else
- cpw = m->cString
- n = 1
- do while n <= len(trim(m->cString))
- cString = stuff( m->cInput, m->n, 1, ;
- chr( asc( substr( m->cpw, m->n, 1 ) ) - m->n ) )
- n = m->n + 1
- enddo
- endif
-
- RETURN m->cString
- *-- EoF: Decode()
-
- FUNCTION Encode
- *----------------------------------------------------------------------
- *-- Programmer..: Angus Scott-Fleming (CIS: 75500,3223)
- *-- Date........: 11/25/1992 (unknown. Stolen from somewhere....)
- *-- Note........: simple encoding for primitive password protection
- *-- Written for.: dBASE IV 1.1+
- *-- Rev. History: 11/25/1992 -- Original
- *-- Mon 08-02-1993 tuning for performance
- *-- Calls.......: None
- *-- Called by...: Any
- *-- Usage.......: Encode(<cInput>)
- *-- Example.....: store encode(cPassWd) to PassWord
- *-- Returns.....: encoded string
- *-- Parameters..: cInput = unencoded string
- *----------------------------------------------------------------------
-
- parameters cInput
- private cString, n
-
- cString = m->cInput
-
- * encode the password
- cpw = m->cString
- n = 1
- do while n <= len(trim(m->cString))
- cString = stuff( m->cString, m->n, 1,;
- chr( asc( substr( m->cpw, m->n, 1 ) ) + m->n ) )
- n = m->n + 1
- enddo
-
- RETURN m->cString
- *-- EoF: Encode()
-
- FUNCTION ExEqual
- *----------------------------------------------------------------------
- *-- Programmer..: Angus Scott-Fleming (CIS: 75500,3223)
- *-- Date........: 11/26/1992 (Improvement on Genifer function)
- *-- Note........: Test for two variables for exact match
- *-- Written for.: dBASE IV 1.1+
- *-- Rev. History: 11/26/1992 - test for TYPE MATCH as well!
- *-- Calls.......: None
- *-- Called by...: Any
- *-- Usage.......: ExEqual(<cInput1>,<cInput2>)
- *-- Example.....: if ExEqual(alias(),"XYZ")
- *-- Returns.....: .T. (exact match), .F. (different types or no match)
- *-- Parameters..: cInput1 = \
- *-- cInput2 = - two memvars to be compared
- *----------------------------------------------------------------------
-
- parameters cInput1, cInput2
-
- RETURN (type("cInput1") = type("cInput2")) .and. ;
- (m->cInput1 = m->cInput2) .and. (m->cInput2 = m->cInput1)
- *-- EoF: ExEqual()
-
- FUNCTION Str_Edit
- *----------------------------------------------------------------------
- *-- Programmer..: Angus Scott-Fleming (CIS: 75500,3232)
- *-- Date........: 05/26/1992
- *-- Notes.......: strips unwanted characters from a string
- *-- (e.g. to normalize international phone numbers
- *-- to nothing but numerals and "-")
- *-- Written for.: dBASE IV 1.1+
- *-- Rev. History: 01/01/1991 -- Original (Pete Carr)
- *-- 05/26/1992 -- Current
- *-- Calls.......: None
- *-- Called by...: Any
- *-- Usage.......: valid required Str_Edit(<cInput>,<cBadChars>)
- *-- Example.....: iphone = space(20)
- *-- @ 6,12 say "Enter Phone# : " get iphone;
- *-- picture replicate("#",len(iphone));
- *-- valid required Str_Edit(iphone, " .+")
- *-- input "011-(49)-345+6789-6790"
- *-- becomes "011-49-3456789-6790"
- *-- Returns.....: .f., then .t.
- *-- Parameters..: cInput = input string
- *-- cBadChars = excluded characters
- *----------------------------------------------------------------------
-
- parameters cInput,cBadChars
- private lrv,nel,nsl,csc,nca,cInput,cBadChars
-
- lRV = .t. && init return value to true
- nEL = len(m->cBadChars) && len of edit characters
- nSL = len(m->cInput) && len of string to edit
-
- cInput = trim(m->cInput) && first, trim string to edit
-
- do while m->nEL > 0 && search string for cBadChars[el]
- cSC = substr(m->cBadChars, m->nEL, 1)
- do while .t. && delete all cBadChars[el] contained in cInput
- nCA = at(m->cSC, m->cInput)
- if m->nCA > 0
- cInput = stuff(m->cInput, m->nCA, 1,"")
- lRV = .f.
- loop
- endif
- exit
- enddo
- nEL = m->nEL - 1
- enddo
-
- do while .t. && search for double spaces and delete
- nCA = at(" ",m->cInput)
- if m->nCA > 0
- cInput = stuff(m->cInput, m->nCA, 1,"")
- lRV = .f.
- else
- exit
- endif
- enddo
-
- * restore string to original length
- cInput = m->cInput + space(m->nSL - len(m->cInput))
- if .not. m->lRV
- keyboard chr(32) + chr(13) && accept and display edited string
- endif
-
- RETURN m->lRV
- *-- EoF: Str_Edit
-
- FUNCTION CapFirst
- *-----------------------------------------------------------------------
- *-- Programmer..: Peter Stevens (HMRS) CIS:100114,301
- *-- Developed from a Borland Help Disk original
- *-- Date........: 11/15/1993
- *-- Notes.......: CAPITALizes a sentence with _some_ applied sense
- *-- The list of words NOT to capitalize can be added to.
- *-- The function was developed to test place names and
- *-- will also work with 3 digits at start before a "The"
- *-- e.g. 123 the avenue comes out as 123 The Avenue but
- *-- 1234 the promenade comes out as 1234 the Promenade
- *-- Written for.: dBASE IV 1.5 (All?)
- *-- Rev. History: ??/??/?? - Original program
- *-- 11/15/1993 Much extended to test words NOT to
- *-- capitalize
- *-- Calls.......: None
- *-- Called by...: Any
- *-- Usage.......: CAPFIRST(cInString)
- *-- Example.....: cADDR1 = CAPFIRST(cADDR1)
- *-- Returns.....: cOutString
- *-- Parameters..: text string to capitalize
- *-----------------------------------------------------------------------
-
- parameters cInString
- private cInString, cOutString,cTalk,cTemp,nLength,nCount,lCap,;
- nTestLen, nCount,nSpaces
-
- *-- Check TALK is OFF
- cTalk = set("TALK")
- set talk off
-
- *-- Set up the variables
- store 1 to nCount,m->nSpaces
- m->lCap = .T.
- m->nTestLen = 1
- m->cInString = m->cInString+space(5) && Note that cInString is
- && NOT TRIMmed
- m->cOutString = "" && Trimming can have unwanted
- && side effects
- m->nLength = LEN(m->cInString) && especially if you want to
- && edit it later
-
- *-- Start capfirsting
- do while m->nCount <= m->nLength
- m->cTemp = substr(m->cInString, m->nCount, 1)
-
- *-- If the character is already a CAP leave it be and go to
- *-- the next
- if isupper("&cTemp.")
- m->cOutString = m->cOutString + upper(m->cTemp)
- m->nCount = m->nCount + 1
- m->lCap = .f.
- loop
- endif
-
- *-- if m->lCap = .t. the m->cTemp is to be a CAPITAL
-
- if m->lCap
- m->cOutString = m->cOutString + upper(m->cTemp)
- m->lCap = .F.
- else
- m->cOutString = m->cOutString + lower(m->cTemp)
- endif
- m->nCount = m->nCount + 1
-
- *-- Here is where its all decided - if the m->cTemp is a space or
- *-- other chars shown between [ ] check what follows to test for
- *-- words we don't want to capitalize.
-
- if m->cTemp $ [ (.-&",/:]
- m->lCap = .T.
- if m->cTemp $ [(- ]
- m->nTestLen = m->nLength - m->nCount
- if m->nTestLen < 1
- m->nTestLen = 2
- endif
- m->cTemp2 = substr(m->cInString,m->nCount,;
- iif(m->nTestLen >= 4,4,m->nTestLen))
- do case
- case substr(m->cTemp2,1,2) = space(2)
- *-- Check to see if at end of the text - signified
- *-- by two spaces
- if m->nCount >= 32 && Adjust this to the longest
- && textstring
- exit && you are going to test
- endif
-
- *-- Test for "a" or "y-" as in "Tyn-y-Gongl"
- case substr(m->cTemp2,1,2) $ "a y-"
- m->cOutString = m->cOutString + ;
- lower(substr(m->cTemp2,1,1))
- m->nCount = m->nCount + 1
-
- *-- Test for two letter words and a space or dash
- case substr(m->cTemp2,1,3) $ ;
- "an by en- in in- is le- op of on on- to "
- m->cOutString = m->cOutString + ;
- lower(substr(m->cTemp2,1,2))
- m->nCount = m->nCount + 2
-
- *-- Test for the occurrence of "the" and its position in
- *-- the string Up to the 5th position it comes out as
- *-- "The"
- case substr(m->cTemp2,1,4) $ "the " .and. m->nCount <= 5
- m->cOutString = m->cOutString + ;
- upper(substr(m->cTemp2,1,1))
- m->cOutString = m->cOutString + ;
- lower(substr(m->cTemp2,2,2))
- m->nCount = m->nCount + 3
-
- *-- Otherwise it comes out as "the"
- case substr(m->cTemp2,1,4) $ "the " .and. m->nCount > 5
- m->cOutString = m->cOutString + ;
- lower(substr(m->cTemp2,1,3))
- m->nCount = m->nCount + 3
-
- *-- Test for 3 letter words with a space or dash
- *-- Or two letter words with a leading dash as in "Co-op"
- case substr(m->cTemp2,1,4) $ ;
- "-op cum cwm for and the- den-"
- m->cOutString = m->cOutString + ;
- lower(substr(m->cTemp2,1,3))
- m->nCount = m->nCount + 3
- endcase
- endif
- endif
- enddo
-
- *-- Organise the outstring for sending back
- m->cOutString = substr(m->cOutString,1,len(m->cInString)-4)
-
- *-- Reset Talk to previous setting
- set talk &cTalk.
-
- RETURN m->cOutString
- *-- EoF: CapFirst()
-
- *----------------------------------------------------------------------
- *-- EoP: STRINGS.PRG
- *----------------------------------------------------------------------